Ext.define('PJ.view.trainingmanagement.ChoisedList2', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.trainingmanagementChoisedList2'],
    isHavePage: false,
    initComponent: function(){
        this.columns = [{
            header: '单位名称',
            dataIndex: 'deptName',
            width: '95%',
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '单位ID',
            dataIndex: 'deptID',
            hidden: true,
            width: '100%',
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }];
        this.store = Ext.create('PJ.' + prototype + '.trainingmanagement.ChoisedList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },
    onDeleteClick: function(button){
        var me = this;
        var records = me.getSelectionModel().getSelection();
        var store = me.getStore();
        for (i in records) {
            store.remove(records[i]);
        }
        store.reload();
    },
    listeners: {
        viewready: function(){
            this.addDocked([{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [this.deleteButton]
            }]);
            // 触发权限过滤事件
            this.fireEvent("permission", this);
            var me = this;
            var name1 = this.up("container").signUpDepartmentNames.getValue();
            var id1 = this.up("container").signUpDepartmentIds.getValue();
            if (name1!=""&&id1!="") {
	            var name = name1.split(',');
	            var id = id1.split(',');
                var model;
                var record = new Array();
                for (i in id) {
                	if(isNaN(i)){
                		continue;
                	}
                    model = Ext.create("PJ.model.trainingmanagement.PreChoisedList");
                    model.set({
                        //列表上的所有字段属性，赋值空
                        "deptName": name[i],
                        "deptID": id[i]
                    });
                    model.commit();//提交model，如果添加此句则列表上不会再显示左上角修改后的标识符
                    record.push(model);
                }
                var store = me.getStore();
                store.each(function(datas){
                    for (var i = 0; i < record.length; i++) {
                        if (datas.data.deptID == record[i].data.deptID) {
                            record.splice(i, 1);
                            i--;
                        }
                    }
                });
                store.add(record);//将刚刚新建的空数组添加到列表中
            }
        },
		/*itemClick: function(){
			var me=this;
			var store =  me.up("container").down("trainingmanagementPreChoisedList2").getStore();
			var record=me.getSelectionModel().getSelection();
            var newParams = {
                deptId: record[0].data.id,
                noDeptID:me.signUpDepartmentIds.getValue()
            };
            // 4.0强制更改store参数写法
            var params = store.proxy.extraParams;
            Ext.apply(params, newParams);
            // grid加载生效
            store.isLoad = true;
            store.load();
			}*/
    }
});
